import manager from './manager';
import project from './project';
import group from './group';
import file from './file';
import translateItem from './translateItem';
import historyList from './history';

class deserialize {
  deserializeProject(value: string): project {
    let json = JSON.parse(value);
    let project = manager
      .buildProject()
      .setProjectName(json.name)
      .setDescription(json.description)
      .setAuthor(json.author)
      .setLICENSE(json.LICENSE)
      .setLanguage(json.language.rawLanguage, json.language.newLanguage)
      .setFileGroup(this.deserializeGroup(json.fileGroup))
      .build();
    return project;
  }
  deserializeGroup(value: any[]): group {
    // let arr: group[] = [];
    // if (value.length > 0) {
    //   value.forEach((v, i) => {
    //     let g = manager.buildGroup(v.name);
    //     v.file.forEach(v => {
    //       g.addFiles(this.deserializeFile(v));
    //     });
    //     if (v.child.length > 0) {
    //       g.addChilds(this.deserializeGroup(v.child));
    //     }
    //     arr.push(g);
    //   });
    // }
    // return arr;
    return null;
  }
  deserializeFile(value: any): file[] {
    let arr: file[] = [];
    let f = manager.buildFile(value.name, '', []);
    value.content.forEach(e => {
      let item = new translateItem(
        e.itemKey,
        e.rawText,
        e.translateText,
        e.isComplete,
        e.lastEdit,
      );
      f.addContent(item);
    });
    arr.push(f);
    return arr;
  }
}
let deserializeProject = new deserialize();
export default deserializeProject;
